<template>
  <div id="app">
    <div class="page-container">
      <transition :name="transitionName">
        <router-view class="content"/>
      </transition>
    </div>
    <TabBar />
  </div>
</template>

<script>
import TabBar from './components/TabBar.vue'

export default {
  name: 'App',
  components: {
    TabBar
  },
  data() {
    return {
      transitionName: 'slide-left'
    }
  },
  watch: {
    $route(to, from) {
      const toDepth = to.meta.index
      const fromDepth = from.meta.index
      this.transitionName = toDepth > fromDepth ? 'slide-left' : 'slide-right'
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  display: flex;
  flex-direction: column;
}

.page-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.content {
  height: calc(100vh - 60px); /* 减去导航栏的高度 */
  position: absolute;
  width: 100%;
  left: 0;
  top: 0;
  background: #fff;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* 高级过渡效果 */
.slide-left-enter-active,
.slide-left-leave-active,
.slide-right-enter-active,
.slide-right-leave-active {
  transition: all 0.4s cubic-bezier(0.55, 0, 0.1, 1);
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  perspective: 1000;
  will-change: transform, opacity;
}

/* 向左滑动的进入和离开效果 */
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}

.slide-left-enter-to {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.slide-left-leave-to {
  opacity: 0;
  transform: translate3d(-30%, 0, 0);
}

/* 向右滑动的进入和离开效果 */
.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}

.slide-right-enter-to {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.slide-right-leave-to {
  opacity: 0;
  transform: translate3d(30%, 0, 0);
}

/* 优化动画性能 */
* {
  -webkit-tap-highlight-color: transparent;
}

.content > * {
  transform: translateZ(0);
}
</style> 